package ui.swing;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;

public class STableRenderer extends DefaultTableCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6468468114154750103L;
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		// TODO Auto-generated method stub
		super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
				row, column);
		TableModel tm = table.getModel();
		int ratePercentCol = table.getColumn("ratePercent").getModelIndex();
		if(tm.getValueAt(row, ratePercentCol).toString().indexOf("-")>=0){
			setForeground(new Color(0,100,0));
		}else if(tm.getValueAt(row, ratePercentCol).toString().indexOf("+")>=0){
			setForeground(new Color(139,0,0));
		}else{
			setForeground(Color.BLACK);
		}
		if(column>1){
			setHorizontalAlignment(SwingConstants.RIGHT);
		}else{
			setHorizontalAlignment(SwingConstants.LEFT);
		}
		table.getColumn("code").setMinWidth(55);
		table.getColumn("name").setMinWidth(40);
		table.getColumn("ratePercent").setMinWidth(40);
		return this;
	}

}
